<?php
/*
*部门接口类
*/
class departmentAppClass extends appBase{
	/*部门分类*/
	public function type(){
		$json['type'] = array();
		$sql = find(array("table" => "department","field" => "distinct type","where" => "order by list"));
		foreach($sql['array'] as $array){
			$json['type'][] = array(
				"name" => $array['type'],
			);
		}
		$json['warn'] = "success";
		return $json;
	}
	/*列表页*/
	public function home(){
		if(!$this->power("department","see")){
			$json['warn'] = "您没有查看部门档案的权限";
		}else{
			//like查询数组
			$like = array(
				"name" => $this->post['name'],//部门名称
			);
			//全等查询数组
			$equal = array(
				"type" => $this->post['type'],//部门分类
			);
			//获取查询结果
			$where = search(array("like" => $like,"=" => $equal));
			$page = $this->page(array("table" => "department","where" => $where,"order" => "list"));
			//数据分析
			$department = array();
			foreach($page['array'] as $array){
				$department[$array['type']][] = array(
					"id" => $array['id'],//部门ID
					"name" => $array['name'],//名称
					"text" => $array['text'],//备注
				);
			}
			$json['department'] = $this->jsonFormat(array("array" => $department));
			//分页信息
			$json['page'] = $page['para'];
			//提示
			$json['warn'] = "success";
		}
		//返回
		return $json;
	}
	/*详情页*/
	public function detail(){
		$department = query("department","id = '".$this->post['id']."'");
		if(!$this->power("department","see")){
			$json['warn'] = "您没有查看部门档案的权限";
		}elseif(empty($this->post['id'])){
			$json['warn'] = "部门ID为空";
		}elseif(empty($department['id'])){
			$json['warn'] = "未找到此部门";
		}else{
			$json['department'] = array(
				"type" => $department['type'],//类型
				"name" => $department['name'],//名称
				"text" => $department['text'],//备注
			);
			$json['warn'] = "success";
		}
		//返回
		return $json;
	}
}
?>